package com.tank.demo.chainOfResponsibility;

import com.tank.demo.abstractFactory.BaseGameObject;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.LinkedList;
import java.util.List;

@Data
@AllArgsConstructor
@ToString
public class ColliderChain implements Collider {

    List<Collider> colliders = new LinkedList<>();

    public ColliderChain(){
        add(new TankAndBulletCollider());
        add(new TankAndTankCollider());
        add(new BulletAndWallCollider());
        add(new TankAndWallCollider());
    }
    public void add(Collider collider){
        colliders.add(collider);
    }

    @Override
    public boolean collide(BaseGameObject o1, BaseGameObject o2) {

        for(int i=0;i<colliders.size();i++){
            if (colliders.get(i).collide(o1, o2)){
                return true;
            }
        }
        return true;
    }
}
